package com.jk.lesson10;

import java.util.Optional;

/**
 * Created by Auser on 2017/3/15.
 */
public class lesson10_5 {
    public static void main(String[] args) {
        Person p = new Person();
        Car c = new Car();
        Insurance i = new Insurance();
        Optional<Person> person = Optional.ofNullable(null);
        System.out.println(getCarInsuranceName(person));
    }

    public static String getCarInsuranceName(Optional<Person> person){
        return person.flatMap(Person::getCar)
                .flatMap(Car::getInsurance)
                .map(Insurance::getName)
                .orElse("Unknown");
    }
}
